#ifndef __INCLUDED_CBL_EVENT_H__
#error "CBL_Event.hpp must not be used directly. Use CBL_Event.h instead."
#else
#ifndef __INCLUDED_CBL_EVENT_HPP__
#define __INCLUDED_CBL_EVENT_HPP__

// -------------------------------------------------------------------------------------------------
//	CEvent
// -------------------------------------------------------------------------------------------------

CEvent::CEvent()
	: m_TypeId(0)
	, m_TypeClassId(ClassTypeInvalid)
	, m_Priority(0)
	, m_pData(NULL)
{
}

// -------------------------------------------------------------------------------------------------

CEvent::CEvent(uint8 _TypeClassId, uint16 _TypeId, int8 _Priority, void* _pData)
	: m_TypeId(_TypeId)
	, m_TypeClassId(_TypeClassId)
	, m_Priority(_Priority)
	, m_pData(_pData)
{
}

// -------------------------------------------------------------------------------------------------
//	CQueuedListener
// -------------------------------------------------------------------------------------------------

CB_FORCEINLINE void CB_INLINE_ATTR CQueuedListener::ProcessEvents(uint32 _MaxCount)
{
    std::vector<EventPtr>::iterator EndIter = m_EventQueue.end();
    std::vector<EventPtr>::iterator Iter = m_EventQueue.begin();
    
    for (uint32 Count(0);
         (Iter != EndIter) && ((_MaxCount==0) || (Count < _MaxCount));
         ++Iter, ++Count)
    {
        OnProcessEvent(*Iter);
	}
    
    m_EventQueue.erase(m_EventQueue.begin(), Iter);
}

// -------------------------------------------------------------------------------------------------
//	CPriorityListener
// -------------------------------------------------------------------------------------------------

CB_FORCEINLINE EventPtr CB_INLINE_ATTR CPriorityListener::Pop()
{
    if (m_EventQueue.empty())
        return EventPtr();

    const EventPtr& rEvent = m_EventQueue.top();
    m_EventQueue.pop();
    return rEvent;
}

// -------------------------------------------------------------------------------------------------

CB_FORCEINLINE bool CB_INLINE_ATTR CPriorityListener::FCompare::operator() (EventPtr& _rLhs, EventPtr& _rRhs)
{
    return _rLhs->GetPriority() < _rRhs->GetPriority();
}

#endif
#endif